package com.sxkiler.demo.generate;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.HashMap;
import java.util.Map;

public class CodeGenerate351 {

    private static String url = "jdbc:mysql://127.0.0.1:3306/springdemo?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&failOverReadOnly=false&allowMultiQueries=true&serverTimezone=GMT%2B8";
    private static String username="springdemo";
    private static String password="springDemo";
    private static String projectPath = "D:/workcodes/springdemo/SimpleDemo/SeataDemo/SeataOrder";
    private static String javapath = "src/main/java/com/sxkiler/demo/seata";
    private static String rspath = "src/main/resources";
    public static void main(String args[]){
        Map<OutputFile,String> pathInfo = new HashMap();
        //设置mapper类的路径
        pathInfo.put(OutputFile.mapper,String.join("/",projectPath,javapath,"dao"));
        pathInfo.put(OutputFile.mapperXml,String.join("/",projectPath,rspath,"mapper"));
        pathInfo.put(OutputFile.entity,String.join("/",projectPath,javapath,"model"));
        //生成空的controller
//        pathInfo.put(OutputFile.controller,String.join("/",projectPath,javapath,"controller"));
        //生成基本的CRUD Service
//        pathInfo.put(OutputFile.service,String.join("/",projectPath,javapath,"service"));
        //生成基本的CRUD ServiceImpl
//        pathInfo.put(OutputFile.serviceImpl,String.join("/",projectPath,javapath,"service.impl"));
        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    builder.author("sxkiler") // 设置作者
//                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .disableOpenDir()
//                            .outputDir("D://")// 指定输出目录
                     ;
                })
                .packageConfig(builder -> {
                    builder.parent("com.sxkiler.demo") // 设置父包名
                            .moduleName("seata") // 设置父包模块名
                            .mapper("dao")
                            .entity("model")
//                            .controller("controller")
//                            .service("service")
//                            .serviceImpl("service.impl")
                            .pathInfo(pathInfo);
                })
                .strategyConfig(builder -> {
                    builder.addInclude("t_order") /* 设置需要生成的表名*/
                    .addTablePrefix("t_", "c_") /* 设置过滤表前缀*/
                    ;

                    builder.entityBuilder()
//                            .enableLombok()
                            .enableLombok()
                            .logicDeleteColumnName("is_delete")
                            .idType(IdType.ASSIGN_UUID)
                    ;
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
